<template>  <!-- 美妆 产品 标签 -->
  <a-card :bordered="false">
    <!--  添加-->
    <a-button @click="ruku" type="primary"icon="plus" style="margin-left: 10px;margin-bottom: 2px">新增</a-button>
    <a-col>
      <a-table
        ref="table"
        bordered
        size="middle"
        rowKey="userId"
        :pagination="ipagination"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        @change="handleTableChange">
       <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical"/>
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a style="color: #ED3F14">删除</a>
          </a-popconfirm>
        </span>
      </a-table>
    </a-col>
    <a-modal v-model="visible" :width="700" title="入库" @ok="handleOk">
      <div >
        <a-form layout="inline" :form="form">
          <a-row style="width: 100%;padding-top: 20px;">
            <a-col>
              <a-form-item  label="标签名字" hasFeedback>
                <a-input style="width: 195px" placeholder="请输入标签名字" v-decorator="['gateway', {}]" />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row style="width: 100%;padding-top: 20px;">
            <a-col>
              <a-form-item  label="英文名字" hasFeedback>
                <a-input style="width: 195px" placeholder="请输入英文名字" v-decorator="['gateway', {}]" />
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-modal>
  </a-card>
</template>

<script>
import { getAction } from '@api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'

export default {
  name: 'productLabel',
  mixins: [JeecgListMixin],
  components: {},
  props: ['value'],
  data() {
    return {
      description: '用户信息',
      cardLoading: true,
      visible: false,
      visible2: false,
      indexStyle:1,
      // 出售设备 数据
      number_chushou:1,
      positionInfo: {},
      columns: [
        {
          title: '#',
          key: 'rowIndex',
          dataIndex: '',
          width: 60,
          align: 'center',
          customRender: (t, r, i) => parseInt(i) + 1
        },
        {
          title: '姓名',
          width: '15%',
          align: 'center',
          dataIndex: 'realname'
        },
        {
          title: '工号',
          width: '',
          align: 'center',
          dataIndex: 'workNo'
        },
        {
          title: '部门',
          width: '',
          align: 'center',
          dataIndex: 'departName'
        },
        {
          title: '公司邮箱',
          width: '',
          align: 'center',
          dataIndex: 'email'
        } ,{
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],

      url: {
        list: '/sys/user/queryByOrgCodeForAddressList',
        listByPosition: '/sys/position/list'
      }
    }
  },
  watch: {
    value: {
      immediate: true,
      handler(orgCode) {
        this.dataSource = []
        this.loadData(1, orgCode)
      }
    },
  },
  created() {
    this.queryPositionInfo()
  },
  methods: {

    loadData(pageNum, orgCode) {
      this.loading = true
      if (pageNum === 1) {
        this.ipagination.current = 1
      }
      // update-begin- --- author:wangshuai ------ date:20200102 ---- for:传过来的部门编码为空全查
      if (!orgCode) {
        getAction(this.url.list, {
          ...this.getQueryParams()
        }).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records
            this.ipagination.total = res.result.total
          }
        }).finally(() => {
          this.loading = false
          this.cardLoading = false
        })
        // update-end- --- author:wangshuai ------ date:20200102 ---- for:传过来的部门编码为空全查
      }else{
        //加载数据 若传入参数1则加载第一页的内容
        getAction(this.url.list, {
          orgCode,
          ...this.getQueryParams()
        }).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records
            this.ipagination.total = res.result.total
          }
        }).finally(() => {
          this.loading = false
          this.cardLoading = false
        })
      }
    },
//筛选 选择日期
    onChange(value, dateString) {
      console.log('Selected Time: ', value);
      console.log('Formatted Selected Time: ', dateString);
    },
// 入库
    ruku() {
      this.visible = true;
    },
    handleOk(e) {
      console.log(e);
      this.visible = false;
    },
    handleEdit() {
      this.visible = true;
    },
// 入库结束

//出售设备
    handleOpen(){
      this.visible2 = true;
    },
    handleOk2(e) {
      console.log(e);
      this.visible2 = false;
    },
    onChange_chushou(number_chushou) {
      console.log('changed', number_chushou);
    },

    searchQuery() {
      this.loadData(1, this.value)
    },
    searchReset() {
      this.queryParam = {}
      this.loadData(1, this.value)
    },

    handleTableChange(pagination, filters, sorter) {
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field
        this.isorter.order = 'ascend' === sorter.order ? 'asc' : 'desc'
      }
      this.ipagination = pagination
      this.loadData(null, this.value)
    },

    // 查询职务信息
    queryPositionInfo() {
      getAction(this.url.listByPosition, { pageSize: 99999 }).then(res => {
        if (res.success) {
          let positionInfo = {}
          res.result.records.forEach(record => {
            positionInfo[record['code']] = record['name']
          })
          this.positionInfo = positionInfo
        }
      })
    }

  }
}
</script>
<style>
.j-address-list-right-card-box .ant-table-placeholder {
  min-height: 46px;
}
</style>
<style scoped>
.j-address-list-right-card-box {
  height: 100%;
  min-height: 300px;
}
.avatar-uploader > .ant-upload {
  width:104px;
  height:104px;
}
.table-page-search-wrapper {
  margin-top: 0px;
  margin-bottom: 2px;
  padding-top: 0px;
}
</style>